package com.dqyt.khjc.controller;

import com.alibaba.fastjson.JSON;
import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;


/**
 * 文件上传管理
 *
 * @author 王植平
 * @version 1.0
 * @date 创建时间：2019年8月20日 上午11:57:24
 * @parameter
 * @returnfileUpload
 * @since
 */
@RestController
public class FileController {

    @Autowired
    public FileService fileService;

    /**
     * @param file 要上传的文件
     * @return
     */
    @RequestMapping(value = "/api/fileUpload", method = {RequestMethod.POST})
    public ResultMsg fileUpload(HttpServletRequest request, @RequestParam("file") MultipartFile file, int optype) {

        ResultMsg resultMsg = fileService.fileUpload(request, file, optype);
        return resultMsg;
    }

    /**
     * @param request
     * @param userId
     * @param token
     * @param files
     * @param optype
     * @return
     */
    @RequestMapping(value = "/api/fileUploadApp", method = {RequestMethod.POST})
    public String fileUploadApp(HttpServletRequest request,
                                @RequestParam long userId,
                                @RequestParam String token,
                                @RequestParam MultipartFile[] files,
                                @RequestParam int optype) {
        ResultMsg resultMsg = fileService.fileUploadApp(request, userId, token, files, optype);
        return JSON.toJSONString(resultMsg);
    }


    /**
     * @param base64Data 要上传的文件
     * @return
     */
    @RequestMapping("/api/base64Upload")
    public ResultMsg base64Upload(HttpServletRequest request, String base64Data, int optype) {
        ResultMsg resultMsg = fileService.base64Upload(request, base64Data, optype);
        return resultMsg;
    }


//    /**
//     * @param file 要上传的文件
//     * @return
//     */
//    @RequestMapping(value = "/api/disfileUpload", method = {RequestMethod.POST})
//    public ResultMsg disfileUpload(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
//        ResultMsg resultMsg = fileService.disfileUpload(request, file);
//        return resultMsg;
//    }
//
//    /**
//     * @param file 要上传的文件
//     * @return
//     */
//    @RequestMapping(value = "/api/disfileUpload2", method = {RequestMethod.POST})
//    public ResultMsg disfileUpload2(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
//        ResultMsg resultMsg = fileService.disfileUpload2(request, file);
//        return resultMsg;
//    }



//    /**
//     * @param file 要上传的文件
//     * @return
//     */
//    @RequestMapping(value = "/api/disfileUpload", method = {RequestMethod.POST})
//    public ResultMsg disfileUpload(HttpServletRequest request, String file) {
////        ResultMsg resultMsg = fileService.disfileUpload(request, file);
//        ResultMsg resultMsg = new ResultMsg();
//        return resultMsg;
//    }

}